<!DOCTYPE html>
<html lang="en">
<head>
    <link rel="stylesheet" href="/static/pear/component/pear/css/pear.css" />
</head>
<body>
<form class="layui-form">
    <div class="mainBox  layui-card-body" style="padding: 0 0;">
        <div class="main-container">
            <div class="layui-form-item">
                <label class="layui-form-label">课程标题*</label>
                <div class="layui-input-block">
                    <input type="text" name="title" value="{$inf.title}" lay-verify="required" placeholder="请输入课程标题" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">Title(EN)*</label>
                <div class="layui-input-block">
                    <input type="text" name="e_title" value="{$inf.e_title}" lay-verify="required" placeholder="请输入Title(EN)" autocomplete="off" class="layui-input">
                </div>
            </div>


            <div class="layui-form-item">
                <label class="layui-form-label">课程评价截止时间</label>
                <div class="layui-input-block">
                    <input type="text" name="deadline" value="{$inf.deadline}" placeholder="课程评价截止时间，单位（天），不填写默认为30天（课程结束后开始计算）" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">关联课程*</label>
                <div class="layui-input-block" style="width: 60%;display: flex">
                    <input type="text" id="course_name" name="course_name" value="{$inf.course_name}" lay-verify="required" placeholder="请选择关联课程" autocomplete="off" class="layui-input">
                    <a onclick="show_field()" class="layui-btn">选择</a>
                    <input type="hidden" name="courseid" id="courseid" class="courseid" value="{$inf.courseid}">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">老师</label>
                <div class="layui-input-block">
                    <select name="teacher" lay-verify="required">
                        {volist name="teacher" id="vo"}
                        <option value="{$vo.id}" {eq name="inf.teacher" value="$vo.id"}selected{/eq}>{$vo.name}</option>
                        {/volist}
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">开课日期*</label>
                <div class="layui-input-block">
                    <input type="text" name="start" value="{$inf.start}" id="start" lay-verify="required" placeholder="请输入开课日期" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">结束日期*</label>
                <div class="layui-input-block">
                    <input type="text" name="end" value="{$inf.end}" id="end" lay-verify="required" placeholder="请输入结束日期" autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">允许回放</label>
                <div class="layui-input-block">
                    <input type="radio" name="playback" value="1" title="允许" {if condition="$inf.playback eq 1"}checked{/if}>
                    <input type="radio" name="playback" value="2" title="不允许" {if condition="$inf.playback eq 2"}checked{/if}>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">直播场景</label>
                <div class="layui-input-block">
                    <input type="radio" name="scene" value="alone" title="活动拍摄" {if condition="$inf.scene eq 'alone'"}checked{/if}>
                    <input type="radio" name="scene" value="ppt" title="三分屏"  {if condition="$inf.scene eq 'ppt'"}checked{/if}>
                    <div class="layui-form-mid layui-word-aux">活动拍摄：有专业直播团队，或老师prefer直接使用屏幕共享（*务必注意：如需直播团队推流则提前联系Danny将第三方推流地址改为永久有效）。 </div>
                    <div class="layui-form-mid layui-word-aux">三分屏：有单独课件上传的排版</div>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">开放范围</label>
                <div class="layui-input-block">
                    <input type="radio" name="range" value="1" title="全员开放" {if condition="$inf.range eq 1"}checked{/if}>
                    <input type="radio" name="range" value="2" title="指定开放"  {if condition="$inf.range eq 2"}checked{/if}>
                </div>
            </div>


            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">培训说明*</label>
                <div class="layui-input-block">
                    <textarea name="content" id="content" class="layui-textarea">{$inf.content}</textarea>
                </div>
            </div>
            <input type="hidden" name="id" value="{$inf.id}">
            {:token_field()}
        </div>
    </div>


    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="user-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
{include file="_Fragment/javascript" /}
<script src="/static/common/jquery-3.6.0.min.js"></script>
<script>
    function show_field() {
        layer.open({
            type: 2,
            title: '选择课程',
            shade: 0.1,
            area: ['800px', '500px'],
            content: '/Classes/showCourse'
        });
    }
    layui.use(['form', 'jquery', 'element', 'tinymce', 'laydate'], function() {
        let form = layui.form;
        let tinymce = layui.tinymce;
        let laydate = layui.laydate;
        let $ = layui.jquery;

        var cont = tinymce.render({
            elem: "#content",
            height: 400,
            images_upload_url: "{:url('Pub/blob')}",
            form: {name:'file'}
        });


        laydate.render({
            elem: '#start'
            ,trigger: 'click'
            ,type: 'datetime'
        });

        laydate.render({
            elem: '#end'
            ,trigger: 'click'
            ,type: 'datetime'
        });



        form.on('submit(user-save)', function(data) {
            let loading = layer.load();
            var content = cont.getContent();
            data.field.content = '';
            data.field.content += content;

            $.ajax({
                url: '/Live/modify',
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'post',
                success: function(result) {
                    layer.close(loading);
                    if (result.status == 0) {
                        layer.msg(result.msg, {
                            icon: 1,
                            time: 1000
                        }, function() {
                            parent.layer.close(parent.layer.getFrameIndex(window
                                .name)); //关闭当前页
                            parent.layui.table.reload("user-table");
                        });
                    } else {
                        layer.msg(result.msg, {
                            icon: 2,
                            time: 1000
                        });
                    }
                }
            })
            return false;
        });
    })
</script>
<script>
</script>
</body>
</html>